import { listProjectinfo } from "@/api/geoInfor/projectinfo";
import { listGeothermalwellinfo } from "@/api/geoInfor/geothermalwellinfo";
const project = {
    state: {
        projects: {},
        wells: {}
    },
    getters: {
        projectno2name: (state, getters) => (projectno) => {
            if (isNaN(parseInt(projectno, 10))) {
                return projectno;

            } else {
                return state.projects[projectno];
            }
        },
        wellno2name: (state, getters) => (wellno) => {
            if (isNaN(parseInt(wellno, 10))) {
                return wellno;

            } else {
                return state.wells[wellno];
            }
        }
    },
    mutations: {
        GET_PROJECTS(state, projects) {
            state.projects = projects;
        },
        GET_WELLS(state, wells) {
            state.wells = wells;
        }
    },
    actions: {
        get_projectno2name({ commit }) {
            return new Promise((resolve, reject) => {
                listProjectinfo({
                    entryname: null,
                    addcode: null,
                    geothermaltype: null,
                    utilizationmode: null,
                    enabled: null,
                }).then((response) => {
                    let obj = {};
                    const projectinfoList = response.rows;
                    projectinfoList.forEach((item) => {
                        obj[item.projectno] = item.entryname;
                    });
                    commit("GET_PROJECTS", obj);
                });
                listGeothermalwellinfo({

                }).then((response) => {
                    let obj = {};
                    const wellList = response.rows;
                    wellList.forEach((item) => {
                        obj[item.wellno] = item.wellname;
                    });
                    commit("GET_WELLS", obj);
                    resolve(obj);
                });
            })
        }

    }
}
export default project;